//app.js
App({
  onLaunch: function () {
    //用户进入小程序后，第一时间获取用户信息并尝试登陆，若登陆成功则将platUser更新
    var that = this;
    wx.login({
      success: function (res) {
        wx.getUserInfo({
          success: function (resp) {
            getApp().globalData.wechatUser = resp.userInfo;
          }
        });
        //尝试登陆
        wx.login({
          success: function (res) {
            wx.getUserInfo({
              success: function (resp) {
                getApp().globalData.wechatUser = resp.userInfo;
              }
            });
            //尝试登陆
            wx.request({
              url: getApp().globalData.host + '/webapp/control/auth.html',
              header: getApp().globalData.header,
              data: { userCode: res.code },
              success: function (loginRes) {
                if (loginRes.data.success) {
                  getApp().globalData.header.cookie = "YNITTC_SOURCE=WECHAT;YNITTC_SESSION_ID=" + loginRes.data.token;
                  getApp().globalData.uploadHeader.cookie = "YNITTC_SOURCE=WECHAT;YNITTC_SESSION_ID=" + loginRes.data.token;
                  getApp().globalData.jsonHeader.cookie = "YNITTC_SOURCE=WECHAT;YNITTC_SESSION_ID=" + loginRes.data.token;
                  getApp().globalData.platUser = loginRes.data.user;
                }
              }
            });
          }
        });
      }
    });
    this.getScreenWidth();
  },
  getScreenWidth: function () {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.globalData.screenWidth = res.windowWidth;
        that.globalData.wechatVersion = res.SDKVersion;
      }
    })
  },
  globalData:{
    wechatUser:{},// errMsg 调用结果；code 用户登录凭证
    platUser:null,
    host: "https://www.ynittc.cn/",
    imgHost: "https://www.ynittc.cn",
    //host: "https://sandbox.ynitc.net/",//测试服务器
    //imgHost: "https://sandbox.ynitc.net",//测试服务器
    //host: "http://localhost/",
    //host: "http://test.ynittc.cn/",
    header: { 'content-type': 'application/x-www-form-urlencoded;charset=utf-8' },
    uploadHeader: { 'content-type': 'multipart/form-data'},
    jsonHeader: {'contentType': 'application/json'},
    servicePhone:'0871-68309903',
    screenWidth:0,
    wechatVersion:1
  }
})